package cn.dida.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.dida.core.Constants;
import cn.dida.model.UserSession;
/**
 * 公共Controller
 * @author weiwei
 * */
public class BaseController {

    protected Log logger = LogFactory.getLog(getClass());


    public UserSession getUserSession(HttpServletRequest request) {
        return (UserSession) request.getAttribute(Constants.USER_SESSION_KEY);
    }
    
    /**
     * 获取请求参数
     * @param request
     * @return Map<String, Object>
     */
  	public Map<String, Object> getSimpleRequestParamMap(HttpServletRequest request) {
  		Map<String, String[]> srcParamMap = request.getParameterMap();
  		Map<String, Object> paramMap = new HashMap<String, Object>();

  		for (String key : srcParamMap.keySet())
  		{
  			
  			if (srcParamMap.get(key).length == 1) 
  			{
  				String value = srcParamMap.get(key)[0];
  				if(null!=value && !"".equals(value.trim())){
  					//value = cleanXSS(value);
  					paramMap.put(key, StringUtils.trimToEmpty(value));
  				}
  			} else {
  				String[] parr = srcParamMap.get(key);
  				String fp = "";
  				for(String str : parr){
  					fp = fp + str + ",";
  				}
  				if(!"".equals(fp)){
  					fp = fp.substring(0, fp.length()-1);
  				}
  				paramMap.put(key, fp);
  			}
  		}

  		return paramMap;

  	}

}
